﻿using System.Data.EntityClient;
using System.Data.SqlClient;

namespace Sissonix.ExtRest.RestManagerModel
{
    class RestManagerHelper
    {
        public static string BuildEFConnectionString(string serverName, string databaseName, string userName, string password)
        {
            string providerName = "System.Data.SqlClient";

            if (serverName == "" || databaseName == "")
                return "";

            // Initialize the connection string builder for the
            // underlying provider.
            SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            sqlBuilder.DataSource = serverName;
            sqlBuilder.InitialCatalog = databaseName;
            sqlBuilder.UserID = userName;
            sqlBuilder.Password = password;

            //sqlBuilder.IntegratedSecurity = true;

            // Build the SqlConnection connection string.
            string providerString = sqlBuilder.ToString();

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();

            //Set the provider name.
            entityBuilder.Provider = providerName;

            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = providerString;

            // Set the Metadata location.
            entityBuilder.Metadata = @"res://*/Model.RestManagerModel.csdl|res://*/Model.RestManagerModel.ssdl|res://*/Model.RestManagerModel.msl";
            return entityBuilder.ToString();
        }
    }
}
